<!-- 面包屑升级 -->
<template>
  <div class="menu-label not-select">
    <el-tabs
      v-model="editableTabsValue"
      type="border-card"
      closable
      @tab-remove="removeTab"
      @tab-click="routerpush"
      @contextmenu.prevent.native="contextMenu"
    >
      <el-tab-pane
        v-for="(item) in editableTabs"
        :key="item.name"
        :label="item.title"
        :name="item.name" 
      >
      </el-tab-pane>
    </el-tabs>
    <transition name="el-zoom-in-top">
      <ul
        v-show="show"
        :style="{ left: left + 'px', top: top + 'px' }"
        class="right-menu"
      >
        <!-- <li @click="reloadFn" v-show="labelTitle ==$store.state.homeStore.editableTabsValue">刷新本页</li> -->
        <li
          @click="rightMenu('currnet')"
          :style="{ pointerEvents: notClick }"
          :class="{ 'not-click': notStyle }"
          v-show="labelTitle != '首页'"
        >
          关闭本页
        </li>
        <!-- <li
          @click="rightMenu('left')"
          :style="{ pointerEvents: notClick }"
          :class="{ 'not-click': notStyle }"
        >
          关闭左边
        </li>
        <li
          @click="rightMenu('right')"
          :style="{ pointerEvents: notClick }"
          :class="{ 'not-click': notStyle }"
        >
          关闭右边
        </li> -->
      </ul>
    </transition>
  </div>
</template>

<script>
export default {
  name: "menuLabel",
  props: {
    editableTabs: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      show: false,
      left: 0,
      top: 0,
      rightClickId: null,
      notClick: "",
      notStyle: false,
      labelTitle: "",

    };
  },
  mounted() {},
  computed: {
    editableTabsValue: {
      get() {
        return this.$store.state.homeStore.editableTabsValue;
      },
      set(value) {
        this.$store.commit('homeStore/setEditableTabsValue', value);
        
      },
    },
  },
  methods: {
    // 跳转
    routerpush(info) {
      // 这些跳转不更新
      let res = this.$store.state.homeStore.routerList.find(
        (c) => c.name == info.name
      );
      this.$store.commit("homeStore/setEditableTabsValue", res.name);
      setTimeout(() => {
        res.name != "file" && this.$router.push({ path:res.path});
      }, 0);
    },
    // 删除
    removeTab(targetName) {
      this.$emit("removeTab", targetName);
    },
    contextMenu(e) {
      if (e.srcElement.id) {
        this.labelTitle = e.target.innerText;
        this.rightClickId = e.srcElement.id.split("-")[1];
        this.show = false;
        let time1 = setTimeout(() => {
          if(e.clientX > 300){
            this.left = e.clientX - 200;
          }else{
            // this.left = e.clientX;
            this.left = e.target.offsetLeft;

          }
          this.top = e.target.offsetTop + 25;
          this.show = true;
          clearTimeout(time1);
        }, 200);
      }
    },
    closeRightMenu() {
      this.show = false;
    },
    reloadFn() {
      this.show = false;
      let { path, name } = this.$store.state.homeStore.routerList.find(
        (c) => c.name == this.rightClickId
      );
      if(path){
        this.$store.commit('homeStore/removeTab2', name);
        if (this.editableTabsValue == name) return this.$store.commit('ChangeIsRouterAlive');
        setTimeout(()=>{
                this.$store.commit("homeStore/setEditableTabsValue", name);
                let obj = {
                    title: name,
                    name: name,
                    path
                }
                this.$store.commit('homeStore/setRouterInfo', obj);
        },200)
      }
      
    },
    rightMenu(type) {
      this.show = false;
      this.$emit("rightMenu", this.rightClickId, type);
    },
  },
  watch: {
    show(val) {
      if (val) {
        document.body.addEventListener("click", this.closeRightMenu);
      } else {
        document.body.removeEventListener("click", this.closeRightMenu);
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.menu-label {
  margin-bottom: 1px;
  position: relative;
}
::v-deep .el-tabs__nav-scroll {
  background: transparent;
  margin-left: 1px;
  width: calc(100% - 20px);
  padding: 2px 0px;
}
::v-deep .el-tabs__nav > div {
  min-width: 80px;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 8px;
  background: white;
  border-radius: 4px;
}
::v-deep .el-tabs__item.is-active {
  width: auto;
  border: none;
  padding-right: 15px;
}
::v-deep .el-tabs__item:first-child.is-active {
  padding-right: 10px;
}
::v-deep .el-tabs--border-card {
  background: transparent;
  border: none;
  box-shadow: none;
}
::v-deep .el-icon-close {
  // position: absolute;
  // top: 3px;
  // right: 2px;
  font-size: 14px !important;
}
::v-deep .el-tabs__nav-prev,
::v-deep .el-tabs__nav-next {
  width: 15px;
  // border: 1px solid #ccc;
  border: none;
  border-radius: 5px;
  text-align: center;
  background: white;
  font-size: 12px;
  height: 26px;
  line-height: 26px;
  top: 2px;
}
::v-deep .el-tabs__nav-prev:hover,
::v-deep .el-tabs__nav-next:hover {
  border: none;
}
.right-menu {
  z-index: 999;
  position: absolute;
  background: white;
  border-radius: 3px;
  padding: 5px 0;
  list-style: none;
  box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.2);
  & > li {
    font-size: 12px;
    width: 88px;
    line-height: 26px;
    text-align: center;
  }
  & > li:hover {
    color: #409eff;
    // background: #409eff;
    cursor: pointer;
  }
  .not-click {
    color: #ccc;
    background: #ededed;
  }
  .not-click:hover {
    color: #ccc;
    background: #ededed;
    cursor: not-allowed !important;
  }
}
::v-deep .el-tabs__content {
  display: none !important;
}
::v-deep .el-tabs__item:first-child {
  width: 40px !important;
  & span {
    display: none;
  }
}
::v-deep .el-tabs__nav-wrap{
  margin-bottom: 0;
}
::v-deep .el-tabs--border-card>.el-tabs__header{
  background-color: #e3e7ed;
}
::v-deep .el-tabs--border-card>.el-tabs__header .el-tabs__item{
  transition: none;
}
::v-deep .el-tabs--border-card>.el-tabs__header .el-tabs__item:first-child{
  margin-left: 6px;
}
::v-deep .el-tabs--top.el-tabs--border-card>.el-tabs__header .el-tabs__item:last-child{
  padding-right: 10px;
}
::v-deep .el-tabs__item {
  padding: 0 10px;
  height: 26px;
  line-height: 26px;
  font-weight: 700;
  position: relative;
  top: 3px;
}
::v-deep .el-tabs__item:focus.is-active.is-focus:not(:active) {
		-webkit-box-shadow: none;
		box-shadow: none !important;
    border: none !important;
	}

</style>
